package com.zr.controller;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class YzmController extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
	// TODO Auto-generated method stub
	super.doGet(req, resp);
}
@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
	resp.setHeader("Pragma", "No-cache");  
    resp.setHeader("Cache-Control", "no-cache");  
    resp.setDateHeader("Expires", 0);  

	BufferedImage bi = new BufferedImage(130, 50, BufferedImage.TYPE_INT_RGB);
	Graphics g = bi.getGraphics();
	g.setColor(Color.WHITE);
	g.setFont(new Font("宋体", Font.BOLD, 60));
	StringBuffer sb=new StringBuffer();
	int x=(int) (Math.random()*10000);
	sb.append(x);
	HttpSession session=req.getSession();
	session.setAttribute("yzm", sb.toString());
	g.drawString(sb.toString(), 0, 50);

	try {		
		boolean a=ImageIO.write(bi, "gif", new File("D:/ezukeworkspace/dingchanxitong/src/main/webapp/11.gif"));
		PrintWriter pw=resp.getWriter();
		pw.write("1");
		pw.flush();
		pw.close();
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
	}

	

}
